package com.zywl.service.impl;

import com.zywl.core.beans.Dictionary;
import com.zywl.core.dao.mapper.sys.DictionaryMapper;
import com.zywl.service.impl.base.BaseServiceImpl;
import com.zywl.service.DictionaryService;
import com.zywl.utils.utils.enums.YesOrNoEnum;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DictionaryServiceImpl extends BaseServiceImpl<DictionaryMapper, Dictionary> implements DictionaryService {
    @Override
    public List<Dictionary> getListAll(String order) throws Exception {
        Map<String, Object> condition = new HashMap<String, Object>();
        condition.put("order", order);
        condition.put("dis_stt", YesOrNoEnum.YES.getKey());
        return mapper.getListByParams(condition);
    }

    @Override
    public Dictionary getDictionaryByTypeAndCode(String type, String code) throws Exception {
        Map<String, Object> condition = new HashMap<String, Object>();
        condition.put("dis_type", type);
        condition.put("dis_code", code);
        condition.put("dis_stt", YesOrNoEnum.YES.getKey());
        condition.put("order", "disSort");
        List<Dictionary> list = mapper.getListByParams(condition);
        if (list != null && !list.isEmpty()) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public List<Dictionary> getDictionaryByType(String type) throws Exception {
        Map<String, Object> condition = new HashMap<String, Object>();
        condition.put("dis_type", type);
        condition.put("dis_stt", YesOrNoEnum.YES.getKey());
        condition.put("order", "dis_sort");
        return mapper.getListByParams(condition);
    }

    @Override
    public List<Dictionary> getTypeList() throws Exception {
        return mapper.getTypeList();
//        return null;
    }

    @Override
    public Integer getMaxByType(String type) throws Exception {
        return mapper.getMaxByType(type);
//        return null;
    }


    @Override
    public Dictionary getDictionaryByTypeAndCodeName(String type, String codeName) throws Exception {
//        List<Dictionary> dictionaries = mapper.getDictionaryByTypeAndCodeName(type, codeName);
//        if (dictionaries != null && !dictionaries.isEmpty()) {
//            return dictionaries.get(0);
//        }
        return null;
    }

    @Override
    public Dictionary getByTypeAndQymc(Map<String, Object> map)throws Exception{
        return mapper.getListByParams(map).get(0);
    }
}
